<template>
  <div class="car-type">
    <slot></slot>
    <section class="years">
      <span
        v-for="(value, key, index) in ImageColor"
        :key="index"
        @click="change(index, key)"
        :class="{ active: index === count }"
        >{{ key }}</span
      >
    </section>

    <section class="list">
      <li v-for="(item, index) in ImageColor[year]"
          @click="sendImageColor(item.Name, item.ColorId)"
         :key="index">
        <span
          :style="{
            background: item.Value,
          }"
        ></span>
        <span>
          {{ item.Name }}
        </span>
      </li>
    </section>
  </div>
</template>

<script>
export default {
  props: ["ImageColor", "first"],
  data() {
    return {
      count: 0,
      year: null
    };
  },
  watch: {
    // data 
    first(newVal) {
      this.year = newVal
    }
  },
  created() {
      // console.log(this.first)
  },
  methods: {
    change(index, key) {
      this.count = index;
      this.year = key;
    },
    // 更改父组件中的状态
    sendImageColor(name, ColorId) {
        console.log(ColorId)
        this.$emit("changeImageColor", {
            name,
            flag: false,
            ColorId
        })
    }
  },
};
</script>

<style lang="scss" scoped>
// 车系颜色
.car-type {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow-y: scroll;
  background: #f4f4f4;
  z-index: 1000;
}

.car-type > div {
  width: 100%;
  height: 100%;
}
.years {
  width: 100%;
  overflow-x: scroll;
  margin: 8px 0;
  background: #fff;
}
.years span {
  font-size: 16px;
  padding-right: 23px;
  line-height: 38px;
}
.years .active {
  color: #3aacff;
}
.list {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: nowrap;
  flex-wrap: wrap;
  background: #fff;
}
.list li {
  width: 172px;
  font-size: 16px;
  line-height: 34px;
  border: 1px solid #3aacff;
  box-sizing: border-box;
  margin: 10px 0 10px 10px;
  border-radius: 3px;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
  span:first-child {
    display: inline-block;
    width: 20px;
    height: 20px;
    margin: 0 10px;
    background: #fe9210;
    box-sizing: border-box;
    border: 1px solid #818181;
  }
}
</style>